import { defineStore } from "pinia";
// 引入数据类型
import  type { categoryStoreStateType } from "./interface/category";

// 引入请求接口
import { reqC1List,reqC2List,reqC3List } from "@/api/product/attr/attr";

export const useCategoryStore = defineStore('category',{
    state:():categoryStoreStateType=>({
        // 存储一级分类的数据
        C1List:[],
        // 搜集一级分类的id
        C1Id:"",
        // 存储二级分类的数据
        C2List:[],
        // 搜集二级分类的id
        C2Id:"",
        // 存储三级分类的数据
        C3List:[],
        // 搜集三级分类的id
        C3Id:""
    }) ,
    actions:{
       async getC1List(){
           let result = await reqC1List ()
           this.C1List = result

        },
          //一级分类下拉菜单触发change事件，获取二级分类数据
        async getC2List(){
            // 清空二级三级数据和id
            this.C2Id='';
            this.C2List=[]
            this.C3Id=''
            this.C3List=[]
            let result = await reqC2List (this.C1Id)
            this.C2List = result
 
         },
           //二级分类下拉菜单触发change事件，获取二级分类数据
         async getC3List(){
            // 清空三级数据和id
            this.C3Id=''
            this.C3List=[]
            let result = await reqC3List (this.C2Id)
            this.C3List = result
 
         }
    }


})

//对外暴露
export default useCategoryStore;